<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-form-model ref="form" :model="mdl" :rules="rules">
                    <a-collapse v-model="panelActiveKeys">
                        <a-collapse-panel key="1" :header="i18n('form.instInfo','租户基本信息')">
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.instNo','租户编号')" prop="instNo">
                                        <a-input :placeholder="i18n('form.instNo','租户编号','input')" v-model="mdl.instNo"/>
                                    </a-form-model-item>
                                </a-col>

                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.email','管理员邮箱')" prop="email">
                                        <a-input :placeholder="i18n('form.email','管理员邮箱','input')" v-model="mdl.email"/>
                                    </a-form-model-item>
                                </a-col>

                            </a-row>
                            <a-row :span="24">

                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.busLiceNo','营业执照编码')">
                                        <a-input :placeholder="i18n('form.busLiceNo','营业执照编码','input')" v-model="mdl.busLiceNo"/>
                                    </a-form-model-item>
                                </a-col>

                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.legalMan','公司法人')">
                                        <a-input :placeholder="i18n('form.legalMan','公司法人','input')" v-model="mdl.legalMan"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>

                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.nameCn','公司中文名')"
                                                       prop="nameCn">
                                        <a-input :placeholder="i18n('form.nameCn','公司中文名','input')" v-model="mdl.nameCn"/>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.nameEn','公司英文名')">
                                        <a-input :placeholder="i18n('form.nameEn','公司英文名','input')" v-model="mdl.nameEn"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.nameCnS','公司简称(中文)')">
                                        <a-input :placeholder="i18n('form.nameCnS','公司简称(中文)','input')" v-model="mdl.nameCnS"/>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.nameEnS','公司简称(英文)')">
                                        <a-input :placeholder="i18n('form.nameEnS','公司简称(英文)','input')" v-model="mdl.nameEnS"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.domain','公司域名')" prop="domain">
                                        <a-input :placeholder="i18n('form.domain','公司域名','input')" v-model="mdl.domain"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.typeName','机构类型')"
                                                       prop="instType">
                                        <a-select
                                            :allowClear="true"
                                            mode="singel"
                                            style="width: 100%"
                                            v-model="mdl.instType" v-if="mdl.instId!='1'"
                                        >
                                            <a-select-option :key="action.typeId" v-for="(action) in instTypeAll">
                                                {{ action.typeName }}
                                            </a-select-option>
                                        </a-select>
                                        <span v-else>{{i18n('form.inst','平台机构')}}</span>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.status','状态')" prop="status">
                                        <a-radio-group defaultValue="ENABLED" buttonStyle="solid" placeholder="状态"
                                                       v-model="mdl.status">
                                            <a-radio-button value="ENABLED">{{i18n('statusMap.ENABLED','启用')}}</a-radio-button>
                                            <a-radio-button value="DISABLED">{{i18n('statusMap.DISABLED','禁用')}}</a-radio-button>
                                        </a-radio-group>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row>
                                <a-col :span="24">
                                    <a-form-model-item :labelCol="{span:3}" :wrapperCol="{span:21}" :label="i18n('form.descp','公司描述')">
                                        <a-textarea :placeholder="i18n('form.descp','公司描述','input')" v-model="mdl.descp"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                        </a-collapse-panel>


                        <a-collapse-panel key="2" :header="i18n('form.contractorInfo','联系人信息')">
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.contractor','联系人')">
                                        <a-input :placeholder="i18n('form.contractor','联系人','input')" v-model="mdl.contractor"/>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.phone','联系电话')">
                                        <a-input :placeholder="i18n('form.phone','联系电话','input')" v-model="mdl.phone"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">

                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.address','地址')">
                                        <a-input :placeholder="i18n('form.address','地址','input')" v-model="mdl.address"/>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.fax','传真')">
                                        <a-input :placeholder="i18n('form.fax','传真','input')" v-model="mdl.fax"/>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                        </a-collapse-panel>


                        <a-collapse-panel key="3" :header="i18n2('argsForm.loginPageConf','登录页配置')">
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('argsForm.ignoreValidCode','忽略验证码')">
                                        <a-radio-group v-model="ignoreValidCode" button-style="solid">
                                            <a-radio-button value="true">
                                                {{i18n2('argsForm.yes','是')}}
                                            </a-radio-button>
                                            <a-radio-button value="false">
                                                {{i18n2('argsForm.no','否')}}
                                            </a-radio-button>
                                        </a-radio-group>
                                    </a-form-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :label="i18n2('argsForm.version','版本')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <a-input  :placeholder="i18n2('argsForm.version','版本','input')" v-model="loginPageConfig.homePageVersion" />
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :label="i18n2('argsForm.loginPageTitle','登录页标题')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <a-input :placeholder="i18n2('argsForm.loginPageTitle','登录页标题','input')"
                                                 @change="updateI18nName(loginPageConfig,'loginPageTitle')" v-model="loginPageTitle">
                                            <my-icon slot="addonAfter" type="iconearth-full" @click="editI18nName(loginPageConfig,'loginPageTitle')" />
                                        </a-input>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :label="i18n2('argsForm.loginPageCopyright','登录页版权')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <a-input :placeholder="i18n2('argsForm.loginPageCopyright','登录页版权','input')"
                                                 @change="updateI18nName(loginPageConfig,'loginPageCopyright')" v-model="loginPageCopyright">
                                            <my-icon slot="addonAfter" type="iconearth-full" @click="editI18nName(loginPageConfig,'loginPageCopyright')"/>
                                        </a-input>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :label="i18n2('argsForm.backGroudLogo','登录页背景图')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <div class="uploadBox">
                                            <a-upload
                                                name="files"
                                                listType="picture-card"
                                                class="avatar-uploader"
                                                :showUploadList="false"
                                                action="/api/api-system/system/core/sysFile/upload"
                                                :headers="headers"
                                                :beforeUpload="beforeUploadBackGroup"
                                                @change="handleLoginBackGroup"
                                                style="width: 100%;height: 100%;"
                                            >
                                                <div v-if="loginBackGroupUrl" class="upload-del" @click.stop="imgDel('loginBackGroup',true)"><a-icon type="close-circle" /></div>
                                                <img v-if="loginBackGroupUrl" :src="loginBackGroupUrl" alt="photo"
                                                     class="userHeadPortrait" style="max-width: 100%;object-fit: cover"/>
                                                <div v-else>
                                                    <a-icon :type="loginBackGroupLoading ? 'loading' : 'plus'"/>
                                                </div>
                                            </a-upload>
                                        </div>
                                        <span class="avatar-uploader-span">{{i18n2('argsForm.backGroupSizeTips','建议上传830*710的背景图片')}}</span>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :label="i18n2('argsForm.colorLogo','登录页彩色logo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                                        <div class="uploadBox">
                                            <a-upload
                                                name="files"
                                                listType="picture-card"
                                                class="avatar-uploader"
                                                :showUploadList="false"
                                                action="/api/api-system/system/core/sysFile/upload"
                                                :headers="headers"
                                                :beforeUpload="beforeUploadLogo"
                                                @change="handleLoginPageLogo"
                                                style="width: 100%;height: 100%;"
                                            >
                                                <div v-if="loginPageLogoUrl" class="upload-del" @click.stop="imgDel('loginPageLogo',true)"><a-icon type="close-circle" /></div>
                                                <img v-if="loginPageLogoUrl" :src="loginPageLogoUrl" alt="photo"
                                                     class="userHeadPortrait" style="max-width: 100%;object-fit: cover"/>
                                                <div v-else>
                                                    <a-icon :type="loginPageLogoLoading ? 'loading' : 'plus'"/>
                                                </div>
                                            </a-upload>
                                        </div>
                                        <span class="avatar-uploader-span">{{i18n2('argsForm.sizeTips','建议上传50*50')}}</span>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12" v-if="!mdl.instId || mdl.instId!='1'">
                                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('argsForm.tenantAdmin','租户管理员账号名')">
                                        <a-input :placeholder="i18n2('argsForm.tenantAdmin','租户管理员账号名')" :disabled="canEdit()"
                                                 v-model="mdl.tenantAdmin" v-decorator="[{rules: [{required: true, message: 'tenantAdmin'}]}]"/>
                                    </a-form-item>
                                </a-col>
                                <a-col :span="12" v-if="mdl.instId">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('argsForm.defaultMainOrg','同步用户默认主部门')" prop="idsClientSecret">
                                        <a-input-group compact style="display: flex;margin-top: 6px;" ref="idsGroupIdInput">
                                            <a-input readOnly v-model="mdl.defaultGroupIdName" style="flex: 1;"/>
                                            <a-button @click="openDefaultGroup"  style="width: 50px">·&nbsp;·&nbsp;·</a-button>
                                        </a-input-group>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                        </a-collapse-panel>
                        <a-collapse-panel key="4" :header="i18n2('list.webConf','网站配置')">
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('webForm.title','首页标题')">
                                        <rx-input-i18n :placeholder="i18n2('webForm.title','首页标题','input')"
                                                       v-model="homePageTitle"/>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('webForm.supportGrade','启用分公司')">
                                        <a-checkbox v-model="supportGrade" ></a-checkbox>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                            <a-row :span="24">
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('webForm.colorLogo','首页彩色logo')" style="margin-top: 10px">
                                        <div class="uploadBox">
                                            <a-upload
                                                name="files"
                                                listType="picture-card"
                                                class="avatar-uploader"
                                                :showUploadList="false"
                                                action="/api/api-system/system/core/sysFile/upload"
                                                :headers="headers"
                                                :beforeUpload="beforeUploadLogo"
                                                @change="handleHomePageLogo"
                                                style="width: 100%;height: 100%;"
                                            >
                                                <div v-if="homePageLogoUrl" class="upload-del" @click.stop="imgDel('homePageLogo',false)"><a-icon type="close-circle" /></div>
                                                <img v-if="homePageLogoUrl" :src="homePageLogoUrl" alt="photo" class="userHeadPortrait" style="max-width: 100%;object-fit: cover" />
                                                <div v-else>
                                                    <a-icon :type="homePageLogoLoading ? 'loading' : 'plus'" />
                                                </div>
                                            </a-upload>
                                        </div>
                                        <span class="avatar-uploader-span">{{i18n2('argsForm.sizeTips','建议上传50*50')}}</span>
                                    </a-form-model-item>
                                </a-col>
                                <a-col :span="12">
                                    <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('webForm.whiteLogo','首页白色logo')" style="margin-top: 10px">
                                        <div class="uploadBox">
                                            <a-upload
                                                name="files"
                                                listType="picture-card"
                                                class="avatar-uploader"
                                                :showUploadList="false"
                                                action="/api/api-system/system/core/sysFile/upload"
                                                :headers="headers"
                                                :beforeUpload="beforeUploadLogo"
                                                @change="handleHomePageLucentLogo"
                                                style="width: 100%;height: 100%;"
                                            >
                                                <div v-if="homePageLucentLogoUrl" class="upload-del" @click.stop="imgDel('homePageLucentLogo',false)"><a-icon type="close-circle" /></div>
                                                <img v-if="homePageLucentLogoUrl" :src="homePageLucentLogoUrl" alt="photo" class="userHeadPortrait" style="max-width: 100%;object-fit: cover" />
                                                <div v-else>
                                                    <a-icon :type="homePageLucentLogoLoading ? 'loading' : 'plus'" />
                                                </div>
                                            </a-upload>
                                        </div>
                                        <span class="avatar-uploader-span">{{i18n2('argsForm.sizeTips','建议上传50*50')}}</span>
                                    </a-form-model-item>
                                </a-col>
                            </a-row>
                          <a-row :span="24">
                            <a-col :span="12">
                              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n2('argsForm.linkLogoLabel','浏览器标签页图标')" style="margin-top: 10px">
                                <div class="uploadBox">
                                  <a-upload
                                      name="files"
                                      listType="picture-card"
                                      class="avatar-uploader"
                                      :showUploadList="false"
                                      action="/api/api-system/system/core/sysFile/upload"
                                      :headers="headers"
                                      :beforeUpload="beforeUpload"
                                      @change="handleLinkLogo"
                                      style="width: 100%;height: 100%;"
                                  >
                                    <div v-if="linkLogoUrl" class="upload-del" @click.stop="imgDel('linkLogo',false)"><a-icon type="close-circle" /></div>
                                    <img v-if="linkLogoUrl" :src="linkLogoUrl" alt="photo" class="userHeadPortrait" style="max-width: 100%;object-fit: cover" />
                                    <div v-else>
                                      <a-icon :type="linkLogoUrlLoading ? 'loading' : 'plus'" />
                                    </div>
                                  </a-upload>
                                </div>
                                <span class="avatar-uploader-span">{{i18n2('argsForm.linkLogoSuggestion','建议上传24*24的ico图标，上传的图标显示在浏览器标签页')}}</span>
                              </a-form-model-item>
                            </a-col>
                          </a-row>
                        </a-collapse-panel>
                    </a-collapse>
                </a-form-model>

            </div>
        </rx-layout>

    </rx-dialog>
</template>
<script>
import OsInstApi from '@/api/user/org/osInst'
import OsInstTypeApi from '@/api/user/org/osInstType'
import {BaseFormModel, RxDialog, RxLayout,RxInputButton,Dialog,JsConstant,TokenUtil,Util} from "@lowcode/jpaas-common-lib";
import SysDicApi from "@/api/system/core/sysDic";
import OsGroupApi from '@/api/user/org/osGroup'
import AppName from "@/assets/js/AppName.js";

export default {
    name: 'OsInstEdit',
    mixins: [BaseFormModel,AppName],
    components: {
        RxDialog,
        RxLayout,
        RxInputButton
    },
    data() {
        return {
            confirmLoading: false,
            instTypeAll: [],

            rules: {
                instNo: [
                    {required: true, message: this.i18nRequired('form.instNo','机构编码'), trigger: 'blur'},
                    {type: "string", min: 1, max: 8, message: this.i18n('list.maxLength','最大长度'), trigger: 'blur'}
                ],
                email: [
                    {required: true, message: this.i18nRequired('form.email','邮件'), trigger: 'blur'},
                ],
                domain: [{required: true, message: this.i18nRequired('form.domain','域名'), trigger: 'blur'}],
                nameCn: [{required: true, message: this.i18nRequired('form.nameCn','机构名'), trigger: 'blur'}],
                instType: [{required: true, message: this.i18nRequired('form.typeName','机构类型'), trigger: 'blur'}],
                status: [{required: true, message: this.i18nRequired('form.status','状态'), trigger: 'blur'}],
            },
            labelOptions: [],
            i18nCurrent:"",
            i18nDefault:process.env.VUE_APP_LANGUAGE,
            panelActiveKeys:['1','2','3','4','5','6'],
            sitetting:{

            },
            siteSettingConfs:{
                loginPageConfig:{},
            },
            loginPageConfig:{
                loginPageTitle:"",
                loginPageCopyright:"",
                loginPageLogo:"",
                loginBackGroup:"",
                homePageVersion:"",
            },
            loginPageTitle:"",
            loginPageCopyright:"",
            headers:{},
            loginPageLogoUrl: '',
            loginBackGroupUrl: '',
            linkLogo:'',
            linkLogoUrl:'',
            linkLogoUrlLoading:false,
            loginPageLogoLoading:false,
            loginBackGroupLoading:false,


            ignoreValidCode:'false',
            homePageTitle:"",
            supportGrade :false,
            homePageLogo: '',
            homePageLucentLogo: '',

            homePageLogoUrl: '',
            homePageLogoLoading:false,

            homePageLucentLogoUrl: '',
            homePageLucentLogoLoading:false,
        }
    },
    created() {
        var token =TokenUtil.getToken() ;
        if (token) {
            this.headers['Authorization'] = 'Bearer ' + token // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
        }
        //this.mdl.adminAccount="admin";
        this.getCurrentI18n();
        this.getLabelOptions();
        this.loadInstTypeAll();
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"osInst",key);
        },
        i18n2(name,text,key){
            return this.$ti18(name,text,"SysConfig",key);
        },
        getCurrentI18n(){
            this.i18nCurrent= window.localStorage.getItem("language");
            if(!this.i18nCurrent){
                this.i18nCurrent=this.i18nDefault;
            }
        },
        openDefaultGroup(){
            let config ={
                single:true,
                dimId:'1',
                showDimId:false,
                tenantId:this.mdl.instId
            }
            Dialog.openGroupDialog({curVm: this,data:config, widthHeight: ['1000px','600px']},function(self,data){
                self.$set(self.mdl,'defaultGroupIdName',data.name);
                self.mdl.defaultGroupId =data.groupId;

            })
        },
        getGroup(groupId){
            let self=this;
            OsGroupApi.getOsGroup(groupId).then(res =>{
                self.$set(self.mdl,'defaultGroupIdName',res.data.name);
            });
        },
        canEdit(){
            if(this.mdl.instId){
                return true;
            }
            return false;
        },
        editI18nName(record,col) {
            let self_ = this;
            var i18nJson=record[col]
            if (i18nJson && typeof i18nJson == "string"){
                //将字符串转换成对象，此处不能用JSON.parse,会转换失败
                i18nJson=eval("(" + i18nJson + ")");
            }
            if(!i18nJson){
                i18nJson={};
            }
            let conifg = {
                curVm: this,
                widthHeight: ['600px', '400px'],
                data: {
                    i18nJson: i18nJson
                }
            }
            Dialog.openI18nDialog(conifg, function (action, data) {
                self_.$set(record, col, JSON.stringify(data));
                //将双引号替换为单引号，防止双引号存储时被转义，影响json转换为对象
                record[col]=record[col].replaceAll('"',"'")
                self_[col]=self_.$i18(record[col])
            });
        },
        updateI18nName(record, col) {
            var i18nJson=record[col]
            if (i18nJson && typeof i18nJson == "string"){
                //将字符串转换成对象，此处不能用JSON.parse,会转换失败
                i18nJson=eval("(" + i18nJson + ")");
            }
            if(!i18nJson){
                i18nJson={};
            }
            i18nJson[this.i18nCurrent]=this[col];
            this.$set(record, col, JSON.stringify(i18nJson));
            //将双引号替换为单引号,防止双引号存储时被转义，影响json转换为对象
            record[col]=record[col].replaceAll('"',"'")
        },
        beforeUpload(file,isBackGroup) {
            const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
            if (!isJpgOrPng) {
                this.errorMessage(this.i18n2('msa.jpgType','只能上传图片!'))
            }
            if(isBackGroup){
                return isJpgOrPng;
            }
            const isLt50KB = file.size / 1024  < 50;
            if (!isLt50KB) {
                this.errorMessage(this.i18n2('msa.jpgSize','图片必须小于50KB!'))
            }
            return isJpgOrPng && isLt50KB;
        },
        errorMessage(content){
            this.$notification['error']({
                message:this.$ti18('rxMsa.actionTips','操作提示'),
                description:content,
                zIndex:9999,
            });
        },
        beforeUploadLogo(file) {
            return this.beforeUpload(file,false);
        },
        beforeUploadBackGroup(file) {
            return this.beforeUpload(file,true);
        },
        handleChange(info, type,isSiteSetting) {
            if (info.file.status === 'uploading') {
                this[type + 'Loading'] = true;
                return;
            }
            if (info.file.status === 'done') {
                var res=info.fileList[info.fileList.length - 1].response;
                if(res.success){
                    this[type]=res.data[0].fileId;
                    this[type + 'Url']=this.getFilePath(res.data[0].fileId);
                    this[type + 'Loading']=false;
                    if(isSiteSetting){
                        this.$set(this.loginPageConfig,type,res.data[0].fileId)
                    }
                }
            }
        },
        getFilePath(fileId){
            if(!fileId){
                return "";
            }
            let token = TokenUtil.getToken();
            fileId=Util.encryptWord(fileId);
            return "/api/api-system/system/core/sysFile/previewFile?fileId=" + fileId + "&accessToken=" + token;
        },
        handleLoginPageLogo(info) {
            this.handleChange(info, 'loginPageLogo',true);
        },
        handleLoginBackGroup(info) {
            this.handleChange(info, 'loginBackGroup',true);
        },
        handleHomePageLogo(info) {
            this.handleChange(info, 'homePageLogo',false);
        },
        handleHomePageLucentLogo(info) {
            this.handleChange(info, 'homePageLucentLogo',false);
        },
        handleLinkLogo(info){
          this.handleChange(info, 'linkLogo');
        },
        imgDel(type,isSiteSetting){
            let typeVaLue=type+"Url";
            this[typeVaLue] = '';
            if(isSiteSetting){
                this.loginPageConfig[type] = '';
            }else{
                this[type] = '';
            }
        },
        i18nRequired(name,text,key){
            let nameVal =this.$ti18(name,text,"osInst",key);
            let requiredVal =this.$ti18('list.required','必填',"osInst");
            return nameVal+requiredVal;
        },
        // 获取机构类型
        loadInstTypeAll() {
            OsInstTypeApi.getOsInstList().then(res => {
                this.instTypeAll = res
            })
        },
        onload_(data) {
            if (!data) {
                this.$set(this.mdl,"status","ENABLED");
            }
            if(data ){
                if(data.sitetting){
                    this.initSiteSetting(data);
                }
                if(data.defaultGroupId){
                    this.getGroup(data.defaultGroupId);
                }
            }
            if(!this.mdl.tenantAdmin){
                this.$set(this.mdl,"tenantAdmin","admin");
            }
        },
        initSiteSetting(data){
            this.sitetting = JSON.parse(data.sitetting);
            if(this.sitetting.confs){
                this.siteSettingConfs = JSON.parse(this.sitetting.confs);
            }
            //登录页配置
            if(this.siteSettingConfs.loginPageConfig){
                this.loginPageConfig=this.siteSettingConfs.loginPageConfig;
                if(this.loginPageConfig.loginPageTitle){
                    let loginPageTitleI18=eval("(" + this.loginPageConfig.loginPageTitle + ")");
                    this.loginPageTitle=loginPageTitleI18[this.i18nCurrent]
                }
                if(this.loginPageConfig.loginPageCopyright){
                    let loginPageCopyrightI18=eval("(" + this.loginPageConfig.loginPageCopyright + ")");
                    this.loginPageCopyright=loginPageCopyrightI18[this.i18nCurrent]
                }
                if(this.loginPageConfig.loginPageLogo){
                    this.loginPageLogoUrl = this.getFilePath(this.loginPageConfig.loginPageLogo);
                }
                if(this.loginPageConfig.loginBackGroup){
                    this.loginBackGroupUrl = this.getFilePath(this.loginPageConfig.loginBackGroup);
                }
            }

            this.ignoreValidCode= this.siteSettingConfs.ignoreValidCode;
            this.homePageTitle = this.siteSettingConfs.homePageTitle;
            this.supportGrade = this.siteSettingConfs.supportGrade;
            this.homePageLogo = this.siteSettingConfs.homePageLogo;
            this.homePageLucentLogo = this.siteSettingConfs.homePageLucentLogo;
            this.linkLogo = this.siteSettingConfs.linkLogoUrl;
            if(this.homePageLogo){
                this.homePageLogoUrl = this.getFilePath(this.homePageLogo);
            }
            if(this.homePageLucentLogo){
                this.homePageLucentLogoUrl = this.getFilePath(this.homePageLucentLogo);
            }
            if(this.linkLogo){
                this.linkLogoUrl = this.getFilePath(this.linkLogo);
            }


        },
        get(id) {
            return OsInstApi.get(id);
        },
        save(values) {
            if(!values.label){
                values.label="";
            }
            //组装租户系统配置
            this.createSitetting();
            values.sitetting = JSON.stringify(this.sitetting);
            return OsInstApi.save(values);
        },
        createSitetting(){
            this.siteSettingConfs.loginPageConfig = this.loginPageConfig;
            this.siteSettingConfs.homePageTitle = this.homePageTitle;
            this.siteSettingConfs.supportGrade = this.supportGrade;
            this.siteSettingConfs.homePageLogo = this.homePageLogo;
            this.siteSettingConfs.ignoreValidCode = this.ignoreValidCode;
            this.siteSettingConfs.homePageLucentLogo = this.homePageLucentLogo;
            this.siteSettingConfs.linkLogoUrl = this.linkLogo;
            this.sitetting.confs = JSON.stringify(this.siteSettingConfs);
        },
        getLabelOptions(){
            var alias="instLabel";
            SysDicApi.getByAlias(alias).then(res=>{
                if(res){
                    for (let i = 0; i < res.length; i++) {
                        this.labelOptions.push({
                            label:res[i].name,
                            value:res[i].value
                        });
                    }
                }
            });
        },
        openDataSource(vm) {
            Dialog.openDataSourceDialog({
                curVm: this,
                widthHeight: ['800px', '600px'],
                data: {appName: this.serviceName}
            }, function (self, data) {
                vm.setVal(data.alias, data.name);
            })
        },
    },

}
</script>
